package bb.lanxing.util.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.databinding.BindingAdapter;
import com.umeng.analytics.pro.d;
import kotlin.Metadata;
import kotlin.jvm.JvmStatic;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;

public final class AlphaLinearLayout extends LinearLayoutCompat {
    public static final Companion Companion = new Companion(null);
    private boolean enable;
    private boolean interceptTouch;
    private final Paint mPaint;

    public AlphaLinearLayout(Context context) {
        this(context, null, 2, null);
        Intrinsics.checkNotNullParameter(context, "context");
    }

    @BindingAdapter(requireAll = false, value = {"setEnable", "interceptTouch"})
    @JvmStatic
    public static final void setMatrixEnable(AlphaLinearLayout alphaLinearLayout, boolean z, boolean z2) {
        Companion.setMatrixEnable(alphaLinearLayout, z, z2);
    }

    public /* synthetic */ AlphaLinearLayout(Context context, AttributeSet attributeSet, int i, DefaultConstructorMarker defaultConstructorMarker) {
        this(context, (i & 2) != 0 ? null : attributeSet);
    }

    public AlphaLinearLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        Intrinsics.checkNotNullParameter(context, "context");
        Paint paint = new Paint();
        this.mPaint = paint;
        this.interceptTouch = true;
        this.enable = true;
        paint.setColor(-1);
        paint.setAlpha(70);
    }

    public final boolean getInterceptTouch() {
        return this.interceptTouch;
    }

    public final void setInterceptTouch(boolean z) {
        this.interceptTouch = z;
    }

    public final boolean getEnable() {
        return this.enable;
    }

    public final void setEnable(boolean z) {
        this.enable = z;
        postInvalidate();
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        if (!this.enable) {
            if (canvas != null) {
                canvas.saveLayer(null, this.mPaint);
            }
            super.dispatchDraw(canvas);
            if (canvas == null) {
                return;
            }
            canvas.restore();
            return;
        }
        super.dispatchDraw(canvas);
    }

    public static final class Companion {
        public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        public static /* synthetic */ void setMatrixEnable$default(Companion companion, AlphaLinearLayout alphaLinearLayout, boolean z, boolean z2, int i, Object obj) {
            if ((i & 4) != 0) {
                z2 = true;
            }
            companion.setMatrixEnable(alphaLinearLayout, z, z2);
        }

        @BindingAdapter(requireAll = false, value = {"setEnable", "interceptTouch"})
        @JvmStatic
        public final void setMatrixEnable(AlphaLinearLayout alphaLinearLayout, boolean z, boolean z2) {
            Intrinsics.checkNotNullParameter(alphaLinearLayout, "alphaLinearLayout");
            alphaLinearLayout.setEnable(z);
            alphaLinearLayout.setClickable(z);
            alphaLinearLayout.setInterceptTouch(z2);
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        if (this.interceptTouch) {
            return !this.enable;
        }
        return super.onInterceptTouchEvent(motionEvent);
    }
}
